package com.algaworks.cursojsf2.financeiro.validator;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

@FacesValidator("com.algaworks.cursojsf2.financeiro.validator.Email")
public class EmailValidator implements Validator {

	@Override
	public void validate(FacesContext contex, UIComponent component, Object value)
			throws ValidatorException {
		if(value != null){
			String email = (String) value;
			if(!email.toLowerCase().contains("@")){
				FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "E-mail inválido!", "E-mail inválido!");
				
				throw new ValidatorException(msg);
			}
				
		}
		
	}
	
}
